use std::collections::HashMap;

#[derive(Eq, PartialEq, Hash, Debug)]
struct Account<'a> {
    username: &'a str,
    password: &'a str,
}

#[derive(Eq, PartialEq, Hash, Debug)]
struct AccountInfo<'a> {
    name: &'a str,
    email: &'a str,
}

type Accounts<'a> = HashMap<Account<'a>, AccountInfo<'a>>;

fn try_login<'a>(accounts: &Accounts<'a>, username: &'a str, password: &'a str) {
    println!("Username:{},Password:{}", username, password);
    println!("Attempting logon ... ");
    let logon = Account { username, password };
    match accounts.get(&logon) {
        Some(info) => {
            println!("Successful logon!");
            println!("Name:{},email:{}", info.name, info.email);
        }
        _ => println!("Login failed!"),
    }
}

fn main() {
    println!("Hello, world!");
    let mut accounts: Accounts = HashMap::new();
    let account = Account {
        username: "j.everyman",
        password: "password123",
    };
    let account_info = AccountInfo {
        name: "John everyman",
        email: "j.everyman@email.com",
    };
    accounts.insert(account, account_info);

    try_login(&accounts, "j.everyman", "password123");
    try_login(&accounts, "j.everyman", "password12");
}
